#ifndef _THREAD_H_
#define _THREAD_H_

#ifdef _WIN32
#   include <windows.h>
#else
#   include <pthread.h>
#endif

class Thread
{
public:
    Thread();
    virtual ~Thread();
    void start();
    virtual void run() = 0;
    virtual void stop() = 0; // stop from outside
    void lock();
    void unlock();
    void join();
    bool isStopped() {
        return !m_running;
    }
private:
#ifdef _WIN32
    HANDLE m_thread;
    CRITICAL_SECTION m_criticalSection;
    static DWORD __stdcall  threadFunc(LPVOID arg);
#else
    pthread_t m_pthread;
    pthread_mutex_t m_mutex;
    static void* threadFunc(void* arg);
#endif
    bool m_running;
};

#endif
